package com.bazhua.bazo.controller;

import com.bazhua.bazo.repository.model.AdminLogin;
import com.bazhua.bazo.repository.model.AdminUpdatePassword;
import com.bazhua.bazo.repository.model.WxUserSearch;
import com.bazhua.bazo.repository.model.result.CommonResult;
import com.bazhua.bazo.repository.model.result.PageListResult;
import com.bazhua.bazo.service.ICommonService;
import com.bazhua.bazo.service.IWechatUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author: starmile
 * @Description:
 * @Create: 2021-01-23 14:14
 **/
@Api(tags = "后台接口")
@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Autowired
    private IWechatUserService wechatUserService;

    @ApiOperation(value = "authorization", notes = "后台修改密码")
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public CommonResult updatePassword(@RequestBody AdminUpdatePassword adminUpdatePassword) {
        return wechatUserService.updatePassword(adminUpdatePassword);
    }

    @ApiOperation(value = "authorization", notes = "后台登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public CommonResult login(@RequestBody AdminLogin adminLogin) {
        return wechatUserService.login(adminLogin);
    }

    @ApiOperation(value = "page", notes = "用户管理分页")
    @RequestMapping(value = "/page", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public PageListResult page(WxUserSearch wxUserSearch) {
        return wechatUserService.page(wxUserSearch);
    }

    @ApiOperation(value = "setAgent", notes = "设置成代理商")
    @RequestMapping(value = "/setAgent", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult setAgent(Long userId) {
        return wechatUserService.setAgent(userId);
    }

    @ApiOperation(value = "setAdmin", notes = "设置成管理员")
    @RequestMapping(value = "/setAdmin", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult setAdmin(Long userId) {
        return wechatUserService.setAdmin(userId);
    }

    @ApiOperation(value = "setUser", notes = "设置普通用户")
    @RequestMapping(value = "/setUser", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public CommonResult setUser(Long userId) {
        return wechatUserService.setUser(userId);
    }
}
